package com.shenfa.dao.systemManager.depart.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.shenfa.bean.Depart;
import com.shenfa.bean.TreeNode;
import com.shenfa.dao.systemManager.depart.DepartDao;

public class DepartDaoImpl implements DepartDao{

	@Autowired
	private SqlMapClientTemplate sqlMapClientTemplate;
	@Autowired
	private SqlMapClient sqlMapClient;
	
	@SuppressWarnings("unchecked")
	public List<Depart> getAll() {
		return sqlMapClientTemplate.queryForList("depart_manager.getAll");
	}

	@SuppressWarnings("unchecked")
	public List<Depart> getAllByOrg(String orgId,int start,int limit) {
		return sqlMapClientTemplate.queryForList("depart_manager.getListByOrg", orgId,start,limit);
	}
	public int queryCount(String orgId) {
		return (Integer)sqlMapClientTemplate.queryForObject("depart_manager.queryCount", orgId);
	}
	public int checkdep(Depart depart) {
		try {
			return (Integer)sqlMapClient.queryForObject("depart_manager.check", depart);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
	}
	
	public void update(Depart depart) {
		sqlMapClientTemplate.update("depart_manager.update", depart);
	}

	public void delete(String id) {
		sqlMapClientTemplate.update("depart_manager.deleteById", id);
	}

	public void add(Depart depart) {
		sqlMapClientTemplate.insert("depart_manager.add", depart);
	}

	public List<TreeNode> getTree(String id) {
		List<TreeNode> list;
		try {
			list=sqlMapClient.queryForList("depart_manager.getTree",id);
		} catch (SQLException e) {
;			e.printStackTrace();
			return null;
		}
		return list;
	}

}
